import 'package:flutter/material.dart';
import 'package:sptapp/moudle/common_info.dart';
import 'package:sptapp/page/index_drawer_page.dart';
import 'package:sptapp/page/login/mail_register.dart';

import '../basic/base_info.dart';
import '../config/const.dart';
import '../moudle/permiss_handler/permission_operate.dart';
import '../page/index_page.dart';
import '../page/login/login.dart';



class SplashPage extends StatefulWidget {
  const SplashPage({super.key,});

  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {

  @override
  void initState() {
    super.initState();
    getLocationPermission(context, (){}, false);
    WidgetsBinding.instance.addPostFrameCallback((callback) async {
      String? token = LocalBaseInfo.getToken();
      if(token == null){
        Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
            settings: const RouteSettings(name: "login"),
            pageBuilder:
                (BuildContext context, Animation animation,
                Animation secondaryAnimation) {
              return const LoginPage();
            }), (route) => false);
      }else{
        // Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
        //     settings: const RouteSettings(name: "login"),
        //     pageBuilder:
        //         (BuildContext context, Animation animation,
        //         Animation secondaryAnimation) {
        //       return const LoginPage();
        //     }), (route) => false);
        _getUserInfo();
      }
    });
  }

  _getUserInfo()async{
    getBaseUserInfo((){
      if(baseUserInfo['updateUser'] == false){
        Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
            settings: const RouteSettings(name: "register"),
            pageBuilder:
                (BuildContext context, Animation animation,
                Animation secondaryAnimation) {
              return const MailRegister(isBanck: false,);
            }), (route) => false);
      }else{
        Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
            settings: const RouteSettings(name: "index"),
            pageBuilder:
                (BuildContext context, Animation animation,
                Animation secondaryAnimation) {
              return const DrawerIndexPage();
            }), (route) => false);
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //屏幕适配初始化
    return Scaffold(
        backgroundColor: defaultBlackBgColor,
        body: Container()
    );
  }
}
